import * as actionTypes from './types'
/**
 * 
 * @param {*} state keepAliveStates
 * @param {*} action { type, payload }
 */
export function KeepAliveReducer(state, action) {
    const { type, payload } = action
    const { keepAliveId, reactElement, nodes } = payload

    switch(type) {
        case actionTypes.CREATING:
            console.log(state);
            return {
                ...state,
                [keepAliveId]: {
                    keepAliveId,
                    reactElement,
                    status: type,
                    nodes: null
                }
            }
        case actionTypes.CREATED:
            console.log(state);

            return {
                ...state,
                [keepAliveId]: {
                    ...state[keepAliveId],
                    status: type,
                    nodes
                }
            }
        default: return state
    }
}